
package com.xian.gaoxiao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.xian.gaoxiao.R;
import com.xian.gaoxiao.model.TaskItem;
import com.xian.gaoxiao.utils.Utilities;

import java.util.List;

public class TaskItemAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<TaskItem> list;

    public TaskItemAdapter(Context context, List<TaskItem> dataList) {
        this.mInflater = LayoutInflater.from(context);
        list = dataList;
    }
    public void setList(List<TaskItem> dataList){
    	list=dataList;
    }
    
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int arg0, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {

            holder = new ViewHolder();

            convertView = mInflater.inflate(R.layout.item_affairitem, null);
            holder.toggleBtn = (ToggleButton) convertView.findViewById(R.id.item_affairitem_tb_status);
            holder.imageView = (ImageView) convertView.findViewById(R.id.item_affairitem_iv_fakecb);
            holder.textView = (TextView) convertView.findViewById(R.id.item_affairitem_tv_content);
          
            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();
        }
        
        TaskItem item= list.get(arg0);
        holder.textView.setText(item.getTitle());
        holder.toggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                Utilities.print(isChecked+"!!!!!!!!!!!!!!");
            }
        });
        

        return convertView;
    }

    private final class ViewHolder {

        public ToggleButton toggleBtn;
        public ImageView imageView;
        public TextView textView;

    }

}
